package com.zixue.heima.helloNetty.EventLoopGroopDemo;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @ClassName : HelloClientFutureChannel3
 * @Description : TODO
 * @Author : chunxiong
 * @Date : 2025/5/8 00:11
 * @Version 1.0
 */
@Slf4j
public class jdkFuture {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        Future<Integer> future = executorService.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                Thread.sleep(2000);
                log.info("2秒耗时 执行计算");
                return 100;
            }
        });
        //主线程如何通信这个线程呢？future对象
        log.info("等待结果");
        Integer integer = future.get();// 阻塞 同步等待别人线程执行完，我拿结果
        log.info("结果：" + integer);
    }
}
